package com.wan37.client.message.received;

import com.google.protobuf.Message;
import com.wan37.client.handler.ClientHandler;
import com.wan37.client.service.cache.ItemServiceCache;
import com.wan37.protobuf.constant.CommonBackpack;
import com.wan37.protobuf.constant.PtoNum;
import com.wan37.protobuf.message.client2server.game.GameBackpack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author : luoyong
 * @date : 2020-07-01 16:24
 **/
@Component(PtoNum.SITEMRESPONSE + "")
public class SItemResponse implements ReceiveMsg {
    private final static Logger logger = LoggerFactory.getLogger(SItemResponse.class);
    private ClientHandler clientHandler = ClientHandler.getInstance();
    @Autowired
    private ItemServiceCache itemServiceCache;

    @Override
    public void execute(Message msg) {
        GameBackpack.SItemResponse sItemResponse = (GameBackpack.SItemResponse) msg;
        int code = sItemResponse.getCode();
        switch (code) {
            case CommonBackpack.ITEM_SUCCESS:
                sItemResponse.getItemList().forEach(item -> {
                    ItemServiceCache.ItemIn itemIn = itemServiceCache.new ItemIn();
                    itemIn.setItem(item);
                    itemServiceCache.getItemInMap().put(item.getBackpack().getBackpackId(), itemIn);
                });
                logger.info(sItemResponse.getContent());
                break;
            default:
                break;
        }
    }
}
